package featuresdemo;

/**
 * Created by pc on 2015/2/12.
 */
class Obj{
    String str = "initial value";
    public String toString(){
        return str;
    }
}
public class PassValueOrReference{
    Obj aObj = new Obj();
    int aInt = 11;
    
    public void changeObj(Obj inObj){
        inObj.str = "changed value";
    }
    public void changePri(int inInt){
          inInt = 22;
    }
    
    public static void main(String[] args)
    {
        PassValueOrReference oRef = new PassValueOrReference();
        //两个对象指向同一个地址，修改第一个对象也会影响到第二个，赋值也是传引用
        PassValueOrReference oRef22 = oRef;
        System.out.println("Before call changeObj() method(oRef): " + oRef.aObj);
        System.out.println("Before call changeObj() method(oRef22): " + oRef22.aObj);
        oRef.changeObj(oRef.aObj);
        System.out.println("After call changeObj() method(oRef): " + oRef.aObj);
        System.out.println("After call changeObj() method(oRef22): " + oRef22.aObj);

        System.out.println("==================Print Primtive=================");
        System.out.println("Before call changePri() method: " + oRef.aInt);
        oRef.changePri(22);
        System.out.println("After call changePri() method: " + oRef.aInt);

    }
}
